<?php
namespace app\system\controller;

use app\common\model\ShopPaymentModel;
use think\Request;

class ShopPaymentController extends BaseController
{

    private $paymentModel;

    /**
     * 初始化
     */
    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->paymentModel = new ShopPaymentModel();
    }

    /**
     * 首页
     * @return mixed
     */
    public function index()
    {
        $this->paymentModel->initData($this->getSiteId()); //初始化数据
        $list = $this->paymentModel->where('site_id', $this->getSiteId())->select();
        $this->assign('list', $list);
        return $this->fetch();
    }


    /**
     * 修改
     */
    public function edit()
    {
        if ($this->request->isAjax()) {
            $data   = $this->request->param();
            $result = $this->validate($data, 'ShopPaymentValidate');
            if ($result !== true) {
                $this->error($result);
            }
            if ($this->paymentModel->editData($data)) {
                $this->success('修改成功', url('index'));
            } else {
                $this->error($this->paymentModel->getError());
            }
        }
        $payId = $this->request->param('pay_id/d');
        $info  = $this->paymentModel->get($payId);
        $this->assign('info', $info);
        return $this->fetch();
    }

}
